<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<base href="<%=basePath%>">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>总店采购</title>
	<meta name="renderer" content="webkit">
 	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="res/layui/css/layui.css">
	<script src="res/js/jquery-2.1.4.min.js" type="text/javascript" ></script>
	<script src="res/layui/layui.js"></script>
	
	<script type="text/html" id="PROLIST_TYPETpl">
  		{{#  if(d.PROLIST_TYPE === '1'){ }}
    		<span class="layui-btn-normal layui-btn-xs" style="color:#fff;padding:4px;">商品采购</span>
  		{{#  } else { }}
  			<span class="layui-btn-warm layui-btn-xs" style="color:#fff;padding:4px;">配料采购</span>
  		{{#  } }}


		
	</script>
	
	<script type="text/html" id="PROLIST_stateTpl">
			{{# if(d.PROLIST_state=='0'){ }}
				<span class="layui-badge layui-bg-gray">未审核</span>
			{{#	}else if(d.PROLIST_state=='1'){ }}
				<span class="layui-badge layui-bg-orange">等待总经理审核</span>
			{{# }else if(d.PROLIST_state=='2'){ }}
				<span class="layui-badge layui-bg-blue">通过审核</span>
			{{# }else if(d.PROLIST_state=='3'){ }}
				<span class="layui-badge">打回</span>
			{{# } }}
	</script>
	
	<script type="text/html" id="demo">
			{{# if(d.PROLIST_state==0 || d.PROLIST_state==1){ }}
				<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="detail">查看审核进度</a>
			{{# }else{ }}
				<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="detail">查看审核记录</a>
			{{# } }}
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">查看详情</a>
	</script>
	
</head>
<body>
	     
 
	
	<div class="demoTable">
	  搜索药品合同：
	  <div class="layui-inline">
	    <input class="layui-input" name="title" id="demoReload" autocomplete="off">
	  </div>
	  
	  <div class="layui-inline">
	      <label class="layui-form-label">开始时间:</label>
	      <div class="layui-input-inline">
	        <input class="layui-input" id="start" name="start" placeholder="yyyy-MM-dd" type="text">
	      </div>
      </div>
      
      <div class="layui-inline">
	      <label class="layui-form-label">结束时间:</label>
	      <div class="layui-input-inline">
	        <input class="layui-input" id="end" name="end" placeholder="yyyy-MM-dd" type="text">
	      </div>
      </div>
	  <button class="layui-btn" data-type="reload">搜索</button>
	</div>
	<div>
		&nbsp;
	</div>
	<div class="site-demo-button" id="layerDemo" style="margin-bottom: 0;">
	  <button data-method="notice" id="add" class="layui-btn">添加采购单</button>
	</div>
 
 
	<table class="layui-hide" id="LAY_table_user" lay-filter="demo"></table> 
	
	<!-- 示例-970 -->
	<ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>
   
	
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
	<script>
	layui.use('table', function(){
	  var table = layui.table;
	//方法级渲染
	  table.render({
	    elem: '#LAY_table_user'
	    ,url: '<%=basePath%>beyondProcurelist/showList.action'
	    ,cols: [[
	      {field:'TIME', title:'订单时间',width:180}
	      ,{field:'PACT_TITLE', title:'使用的合同',width:100}
	      ,{field:'PROLIST_TYPE', title:'采购类型',width:100, sort: true,templet: '#PROLIST_TYPETpl'}
	      ,{field:'STAFF_NAME', title:'经办人',width:80}
	      ,{field:'PROLIST_money', title:'采购总金额(元)',width:150, sort: true}
	      ,{field:'PROLIST_DPCOUNT', title:'实际采购数量',width:120}
	      ,{field:'PROLIST_state', title:'审核状态',width:135,sort: true,templet: '#PROLIST_stateTpl'}
	      ,{fixed :'right',width:200,align:'center',toolbar:'#demo'}
	    ]]
	    ,id: 'testReload'
	    ,page: true 
	    ,height: 500
	  });
	  
	  var $ = layui.$, active = {
	    reload: function(){
	      var demoReload = $('#demoReload');
	      var start=$("#start");
	      var end=$("#end");
	      //执行重载
	      table.reload('testReload', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	        ,where: {
	         
	        	  title: demoReload.val(),
	        	  start: start.val(),
	        	  end: end.val()
	          
	        }
	      });
	    }
	  };
	  
	//监听工具条
	table.on('tool(demo)',function(obj) {
		var data = obj.data;
		if(obj.event === 'detail'){
			if(data.PROLIST_state!=0){
				information(data.PROLIST_ID);//查询审核情况的方法
			}else{
				layer.msg('等待审核',{icon: 5,anim: 6});
			}
		}else if(obj.event === 'del') {
				checkMsg(data.PACT_TYPE, data.PROLIST_ID);
			
		}
	});
	  $('.demoTable .layui-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
	
	layui.use(['form', 'layedit', 'laydate'], function(){
		  var form = layui.form
		  ,layer = layui.layer
		  ,layedit = layui.layedit
		  ,laydate = layui.laydate;
		  
		  //日期
		  laydate.render({
		    elem: '#start'
		  });
		  laydate.render({
		    elem: '#end'
		  });
		  
		  //创建一个编辑器
		  var editIndex = layedit.build('LAY_demo_editor');
		 
		  //自定义验证规则
		  form.verify({
		    title: function(value){
		      if(value.length < 5){
		        return '标题至少得5个字符啊';
		      }
		    }
		    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
		    ,content: function(value){
		      layedit.sync(editIndex);
		    }
		  });
		  
		  //监听指定开关
		  form.on('switch(switchTest)', function(data){
		    layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
		      offset: '6px'
		    });
		    layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
		  });
		  
		  //监听提交
		  form.on('submit(demo1)', function(data){
		    layer.alert(JSON.stringify(data.field), {
		      title: '最终的提交信息'
		    })
		    return false;
		  });
		  
		  
		}); 
	});
	
	$("#add").on('click',function(){
		layer.open({
	        type: 2,
	        title:"添加采购单"
	        ,area: ['700px','500px']
	        ,content: 'pages/procurelistAdd.jsp'
		});
	        
	})
	
	
	/**
		查看审核情况
	*/
	function information(entryId){
		openIndex = layer.open({
			type : 2//样式
			,
			skin : 'layui-layer-molv'//样式
			,
			area : [ '50%', '70%' ],
			title : "审核记录"//标题 
			,
			id : 'queryExam' //防止重复弹出
			,
			content : 'pages/SH/queryExam.jsp?entryId='+entryId,
			shade : [ 0.8, '#393D49' ] //显示遮罩 
			,
			shadeClose : true//点击也能遮罩层关闭
			,
			anim : 2
		//弹出动画 
		});
	}

	/**
		查看详情
	*/
	function checkMsg(type, prolistId){
		var url = 'exam/findCaiGById.action';
		$.post(url,{"prolistId" : prolistId,"proType":type},function(info) {
			
			var tablestr = '<table style="width:80%;margin:auto;margin-top:40px;margin-bottom:40px;" class="layui-table"><thead><tr><th align="center">名称</th><th>数量</th><th>小计</th></tr></thead><tbody>';
			
			for(i=0; i<info.length; i++){
				var obj = info[i];
				if(type==1){
					tablestr += '<tr><td>'+obj.WARE_NAME+'</td><td>'+obj.PROLISTMX_COUNT+'</td><td>'+obj.PROLISTMX_MONEY+'</td>';
				}else{
					tablestr += '<tr><td>'+obj.DOS_NAME+'</td><td>'+obj.DOSING_PROLISTMX_COUNT+'</td><td>'+obj.DOSING_PROLISTMX_MONEY+'</td>';
				}
			}
			tablestr += '</tbody></table>';
			layer.open({
				type : 1//样式
				,
				skin : 'layui-layer-molv'//样式
				,
				area : [ '60%'],
				title : "详情"//标题
				,
				id : 'xq' //防止重复弹出
				,
				content : tablestr,
				shade : [ 0.8, '#393D49' ] //显示遮罩
				,
				shadeClose : true//点击也能遮罩层关闭
				,
				anim : 2
			//弹出动画 
			});
		});
	}

	
	</script>
</body>
</html>